<!-- UserModel.php-->
<?php 
/*	require '../common/ConnDB.php';
	require '../common/config.php';*/
	require 'Model.php';
	class typeModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function gettypeList(){
			$sql = 'select * from noveltype';
			$data = $this->conn->query($sql);
			//$this->conn = new ConnDB();
			return $data;
		}

		
		

		function getUserByID($id){
			$sql = "select * from noveltype where tid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function Updatetype($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}
		  	$novel = array(
				
				'typename' => $_POST['typename'],
				'tid' => $_POST['tid'],
				
				);
			$sql="update noveltype set tid='$novel[tid]',typename='$novel[typename]'where tid=".$novel['tid'];
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function addtype($data){
			//如果选择了照片，则上传照片文件
			if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}
			$user = array(
				'tid' =>'',
				'typename' => $data['typename'],
				'tid' => $data['tid'],
				
				);
			$keys = implode(',',array_keys($user));
			$values = implode("','",array_values($user));
			/*$sql = "insert into users values ('$user[uid]','$user[uname]','$user[password]','$user[gender]','$user[birthdate]','$user[hobby]','$user[degree]','$user[intro]','$user[pic]')";*/
			$sql="insert into noveltype ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function Deltype($id){
			$sql = "Delete from noveltype where tid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}
	}
 ?>